#!/bin/bash
# 初始化docker 并且切换阿里云的镜像库
#install docker
install_docker() {
yum install -y yum-utils
test -d /etc/docker
if [[ $? -eq 0 ]];then
echo "docker已经安装完毕!!!"
else
mkdir -p /etc/docker
yum-config-manager --add-repo  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#yum install -y --setopt=obsoletes=0 docker-ce-18.09.4-3.el7
yum install -y --setopt=obsoletes=0 docker-ce docker-ce-cli containerd.io
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://gpkhi0nk.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl enable docker
systemctl restart docker
echo "docker已经安装完毕!!!"
fi
}
#卸载docker
remove_docker() {
    systemctl stop docker
    systemctl disable docker
	yum remove docker-ce docker-ce-cli containerd.io
	yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine \
				  docker-ce \
				  docker-ce-cli \
				  containerd.io
	rm -rf /var/lib/docker
}
case $1 in
 'install')
	install_docker
 ;;
 'remove')
	remove_docker
 ;;
 *)
	echo "please input [install,remove]"
    exit;
 esac